package top.tangyh.lamp.care.service.impl;

import cn.hutool.core.bean.BeanUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.tangyh.lamp.care.mapper.BHl7GmMapper;
import top.tangyh.lamp.care.service.BHl7GmService;
import top.tangyh.basic.base.service.impl.SuperServiceImpl;
import top.tangyh.lamp.care.manager.BHl7GmManager;
import top.tangyh.lamp.care.entity.BHl7Gm;
import top.tangyh.lamp.care.vo.result.GmOutVO;
import top.tangyh.lamp.care.vo.save.BHl7GmSaveVO;
import top.tangyh.lamp.care.vo.save.GmInfoInVO;
import top.tangyh.lamp.care.vo.update.BHl7GmUpdateVO;
import top.tangyh.lamp.care.vo.result.BHl7GmResultVO;
import top.tangyh.lamp.care.vo.query.BHl7GmPageQuery;

import java.util.List;

import static top.tangyh.lamp.common.constant.CommonConstant.YES_NUMBER;

/**
 * <p>
 * 业务实现类
 * 过敏史
 * </p>
 *
 * @author zqb
 * @date 2024-07-15 11:24:55
 * @create [2024-07-15 11:24:55] [zqb] [代码生成器生成]
 */
@Slf4j
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class BHl7GmServiceImpl extends SuperServiceImpl<BHl7GmManager, Long, BHl7Gm> implements BHl7GmService {

    private final BHl7GmMapper bHl7GmMapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addGmInfo(GmInfoInVO gmInfoInVO) {
        BHl7Gm gmPO = new BHl7Gm();
        gmPO.setGmName(gmInfoInVO.getGmName());
        gmPO.setPatientIdent(gmInfoInVO.getPatientIdent());
        gmPO.setHospitalNumber(gmInfoInVO.getHospitalNumber());
        gmPO.setIsDiy(YES_NUMBER);
        bHl7GmMapper.insert(gmPO);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateGmInfo(GmInfoInVO gmInfoInVO) {
        BHl7Gm gmPO = bHl7GmMapper.selectById(gmInfoInVO.getId());
        if (gmPO != null) {
            BHl7Gm updateGm = new BHl7Gm();
            updateGm.setId(gmPO.getId());
            gmPO.setGmName(gmInfoInVO.getGmName());
            bHl7GmMapper.updateById(gmPO);
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteGmInfo(Long id) {
        BHl7Gm gmPO = bHl7GmMapper.selectById(id);
        if (gmPO != null) {
            BHl7Gm delGmPO = new BHl7Gm();
            delGmPO.setId(id);
            delGmPO.setIsDeleted(YES_NUMBER);
            bHl7GmMapper.updateById(delGmPO);
        }
    }

    @Override
    public List<GmOutVO> listGmOutVO(String hospitalNumber) {
        List<BHl7Gm> list=bHl7GmMapper.selectGmListByHospitalNumber(hospitalNumber);
        List<GmOutVO> listGmOutVO= BeanUtil.copyToList(list,GmOutVO.class);
        return listGmOutVO;
    }
}


